/*
 * @Author: cl
 * @Description: 插件工具
 * @Date: 2023-05-17 14:35:52
 * @LastEditTime: 2023-07-05 15:29:03
 * @FilePath: \vue3scaffold\src\plugins\index.ts
 * @LastEditors: chenli chenli@kcwl.com
 */
import { App, defineAsyncComponent } from "vue";
import { setTailwindcss } from "./tailwindcss";
// import VeeValidate from 'vee-validate';


//设置插件
export function setPlugins(app: App) {
  setComponents(app);
  setTailwindcss();
  // app.use(VeeValidate);
}

/**
 * 自动注册组件
 * @param app 上下文
 */
function setComponents(app: App) {
  const components = import.meta.glob("@/components/*.vue",{ eager: true });
  Object.keys(components).forEach((keys) => {
    const name = keys.split("/").pop()?.split(".").shift() as string;
    // app.component(name, defineAsyncComponent(components[keys] as any));
    app.component(name, (components[keys] as any).default);
  });

  // const components = import.meta.globEager("@/components/*.vue");
  // Object.keys(components).forEach((keys) => {
  //   const name = keys.split("/").pop()?.split(".").shift() as string;
  //   app.component(name, (components[keys] as any).default );
  // });
  // for (const [key, myValue] of Object.entries(components)) {
  //     const name = key.slice(key.lastIndexOf('/') + 1, key.lastIndexOf('.'));
  //     console.log(myValue);
  //     app.component(name, defineAsyncComponent(myValue as any));
  //   }
}
